package com.zhs.gccs.fragment.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gyf.immersionbar.ImmersionBar;
import com.zhs.gccs.R;
import com.zhs.gccs.activity.LoginActivity;
import com.zhs.gccs.activity.app.AppVersionActivity;
import com.zhs.gccs.activity.gb.PDFActivity;
import com.zhs.gccs.activity.gb.PDFAssetActivity;
import com.zhs.gccs.fragment.BaseFragment;
import com.zhs.gccs.utils.DialogUtils;
import com.zhs.gccs.utils.SharedPrefHelper;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MineFragment extends BaseFragment implements View.OnClickListener{
    @BindView(R.id.tv_user)
    TextView tv_user;
    @BindView(R.id.tv_user_org)
    TextView tv_user_org;
    @BindView(R.id.rl_header)
    View rl_header;

    @BindView(R.id.tv_exit)
    View tv_exit;
    @BindView(R.id.tv_attach_download)
    TextView tv_attach_download;
    @BindView(R.id.tv_app_version)
    TextView tv_app_version;
    @BindView(R.id.tv_app_helper)
    TextView tv_app_helper;


    @Override
    protected int getLayout() {
        return R.layout.fragment_mine;
    }
    public static MineFragment newInstance() {
        Bundle args = new Bundle();
//        args.putSerializable("project", project);
        MineFragment fragment = new MineFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ImmersionBar.with(getActivity()).transparentBar().init();
        rl_header.setPadding(0, ImmersionBar.getStatusBarHeight(this), 0, 0);
//        View titleBar = view.findViewById(R.id.toolbar);
//        ImmersionBar.setTitleBar(getActivity(), titleBar);
//        View statusBarView = view.findViewById(0);
//        ImmersionBar.setStatusBarView(getActivity(), statusBarView);
        tv_attach_download.setOnClickListener(this);
        tv_app_version.setOnClickListener(this);
        tv_app_helper.setOnClickListener(this);
        tv_exit.setOnClickListener(this);
        tv_user.setText(SharedPrefHelper.getInstance().getUserNickName());
        tv_user_org.setText(SharedPrefHelper.getInstance().getUserOrgName());
    }

//    @Override
//    public boolean immersionBarEnabled() {
//        return false;
//    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_exit:
            {
                DialogUtils.showPromote2(context, "是否退出", null, new DialogUtils.OnConfirmListener() {
                    @Override
                    public void onConfirmed() {
                        SharedPrefHelper.getInstance().setLastLoginTime(0);
                        Intent intent = new Intent(context, LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        context.startActivity(intent);
                    }
                });
                break;
            }
            case R.id.tv_app_version:{
                Intent intent = new Intent(context, AppVersionActivity.class);
                context.startActivity(intent);
                break;
            }
            case R.id.tv_app_helper:
            {
                Intent intent = new Intent(context, PDFAssetActivity.class);
                intent.putExtra(PDFActivity.intent_title,"核查APP用户手册");
                intent.putExtra(PDFActivity.intent_url, "用户手册-高标准农田项目核查系统-离线版.pdf");
                context.startActivity(intent);
                break;
            }
        }
    }


}
